package xyz.syyrjx.blog.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import xyz.syyrjx.blog.entity.Result;

import javax.servlet.http.HttpServletRequest;

@ControllerAdvice
public class FinalExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(FinalExceptionHandler.class);

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result gotoErrorPage(HttpServletRequest request, Exception exception){
        String url =new String(request.getRequestURL()) ;
        logger.error("地址链接{}发生异常{}", url ,exception.toString());
        return Result.fail("服务器错误"+exception);
    }
}
